package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.db.table.I_LocationLayoutCurrent;
import com.openbravo.bean.LocationLayoutCurrent;
import com.openbravo.bean.Location;
import com.openbravo.bean.Product;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class LocationLayoutCurrentDAO extends ModifiedLogDAO<LocationLayoutCurrent>{

	public LocationLayoutCurrentDAO(I_Session s) {
		super(s);
	}

	@Override
	public LocationLayoutCurrent readValues(DataRead dr,LocationLayoutCurrent obj) throws BasicException {
		if(obj==null)
			obj=new LocationLayoutCurrent();
		obj.setId(dr.getString(1));
		obj.setLocationLayoutId(dr.getString(2));
		obj.setProductId(dr.getString(3));
		obj.setAttrsetinstId(dr.getString(4));
		obj.setUnits(dr.getDouble(5));
		obj.setLastModified(dr.getTimestamp(6));
		return obj;
	}

	@Override
	public TableDefinition getTable() {
		return new TableDefinition(s, "LOCATION_LAYOUT_CURRENT", new Field[] {
				new Field(I_LocationLayoutCurrent.ID, Datas.STRING, Formats.STRING),
				new Field(I_LocationLayoutCurrent.LOCATIONLAYOUT, Datas.STRING, Formats.STRING,
						Location.class),
				new Field(I_LocationLayoutCurrent.PRODUCT, Datas.STRING, Formats.STRING,
						Product.class),
				new Field(I_LocationLayoutCurrent.ATTRIBUTESETINSTANCE_ID, Datas.STRING, Formats.STRING),		
				new Field(I_LocationLayoutCurrent.UNITS, Datas.DOUBLE, Formats.DOUBLE),
				new Field(I_LocationLayoutCurrent.LASTMODIFIED, Datas.TIMESTAMP, Formats.TIMESTAMP)
		},new int[] { 0 });
	}

	@Override
	public void writeInsertValues(DataWrite dp, LocationLayoutCurrent obj)
			throws BasicException {
		dp.setString(1,obj.getId());
		dp.setString(2,obj.getLocationLayoutId());
		dp.setString(3,obj.getProductId());
		dp.setString(4,obj.getAttrsetinstId());
		dp.setDouble(5,obj.getUnits());
		dp.setTimestamp(6,obj.getLastModified());
	}

	@Override
	public Class getSuportClass() {
		return LocationLayoutCurrent.class;
	}
}
